<template>
  <div>
    <def-layout type="col0-24" :page="page" @invoke="invoke">
      <div slot="search" class="form-items">
        <el-form-item>
          <el-input v-model="formSearch.keyword" placeholder="名称/编码" />
        </el-form-item>
        <el-form-item>
          <el-select v-model="formSearch.used" placeholder="状态">
            <el-option
              v-for="item in constants.used.values()"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <form-area v-model="formSearch.areaIds" :def-show="true" placeholder="选择地区" :change-on-select="true" :level="3" />
        </el-form-item>
        <el-form-item>
          <duty-users v-model="formSearch.salesmanId" size="mini" mode="search" placeholder="业务员" :duty-id="$store.state.settings.wmsConf.purchase.dutyId[1]" />
        </el-form-item>
        <el-form-item>
          <el-select v-model="formSearch.isBind" placeholder="绑定状态">
            <el-option
              v-for="item in constants.isBind.values()"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </div>
      <div slot="content" class="grid">
        <page-grid v-if="self!=null" :parent="self">
          <div slot="columns">
            <el-table-column prop="used" align="center" label="状态" width="100">
              <template slot-scope="scope">
                <column-filter v-model="scope.row.used" type="used" @click="filter" />
              </template>
            </el-table-column>
            <el-table-column prop="no" align="center" label="编码" width="150" />
            <el-table-column prop="name" align="center" label="名称" width="290" />
            <el-table-column prop="mobile" align="center" label="手机" width="150" />
            <el-table-column prop="updateTime" sortable align="center" label="无活跃天数" width="150">
              <template slot-scope="scope">
                <label>{{ scope.row.silence }}天</label>
              </template>
            </el-table-column>
            <el-table-column prop="orderCount" sortable align="right" label="供货次数" width="100" />
            <el-table-column prop="sales" sortable align="right" label="交易额" width="100" />
            <el-table-column prop="weight" sortable align="right" label="总重" width="100" />
            <el-table-column prop="area" align="center" label="地区" width="150" />
            <el-table-column prop="createTime" sortable align="center" label="创建时间" width="150" />
          </div>
        </page-grid>
      </div>
    </def-layout>
  </div>
</template>
<script>
import adminSupport from 'lola-admin-support-el'

export default {
  name: 'SupplierManage',
  components: {
  },
  mixins: [adminSupport.mixins.index],
  data() {
    return {
      name: 'SupplierManage',
      formSearch: { keyword: '', used: '', areaIds: '', isBind: '' },
      self: null
    }
  },
  created() {
    this.init()// 页面自定义初始化
  },
  methods: {
    init() {
      var that = this
      that.loadData()// 加载数据(按钮+列表) 扩展需重写该方法
      this.self = that
    },
    search() {
      const queryList = []
      if (!String.isNullOrEmpty(this.formSearch.keyword)) {
        queryList.push({ 'key': 'o.name', 'value': {
          'o.name': this.formSearch.keyword,
          'o.no': this.formSearch.keyword
        }, 'oper': ':', 'join': 'andOr' })
      }
      if (!String.isNullOrEmpty(this.formSearch.used) && this.formSearch.used !== 'All') queryList.push({ 'key': 'o.used', 'value': this.formSearch.used, 'oper': '=', 'join': 'and' })
      if (!String.isNullOrEmpty(this.formSearch.salesmanId)) queryList.push({ 'key': 'o.salesmanId', 'value': this.formSearch.salesmanId, 'oper': '=', 'join': 'and' })
      if (!String.isNullOrEmpty(this.formSearch.isBind)) {
        if (this.formSearch.isBind === 0) {
          queryList.push({ 'key': 'o.salesmanId', 'value': '', 'oper': 'null', 'join': 'and' })
        } else {
          queryList.push({ 'key': 'o.salesmanId', 'value': '', 'oper': '!=null', 'join': 'and' })
        }
      }
      if (!String.isNullOrEmpty(this.formSearch.areaIds)) {
        queryList.push({ 'key': 'o.areaIds', 'value': this.formSearch.areaIds, 'oper': ':', 'join': 'and' })
      }
      this.dataGrid.params.queryList = queryList
      this.refresh()
    },
    bindSearch() {
      this.formSearch = { keyword: '', used: '', areaIds: '', isBind: '' }
    }
  }
}
</script>
